let css = [
  { local: 'lib/index.css', cdn: 'https://cdn.jsdelivr.net/npm/vant@next/lib/index.css' },
  { local: 'app/app.css', cdn: 'app/app.css', stamp: true },
];

let js = [
  { local: 'lib/vue.global.js', cdn: 'https://cdn.jsdelivr.net/npm/vue@3.0.11/dist/vue.global.prod.js' },
  { local: 'lib/vuex.global.min.js', cdn: 'https://cdn.jsdelivr.net/npm/vuex@4.0.0/dist/vuex.global.min.js' },
  { local: 'lib/vuex-persistedstate.umd.js', cdn: 'https://cdn.jsdelivr.net/npm/vuex-persistedstate@4.0.0-beta.3/dist/vuex-persistedstate.umd.js' },
  { local: 'lib/vue3-sfc-loader.min.js', cdn: 'https://cdn.jsdelivr.net/npm/vue3-sfc-loader@0.7.3/dist/vue3-sfc-loader.min.js' },
  { local: 'lib/lodash.min.js', cdn: 'https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js' },
  //{ local: 'lib/axios.min.js', cdn: 'https://cdn.jsdelivr.net/npm/axios@0.21.1/dist/axios.min.js' },
  { local: 'lib/vant.min.js', cdn: 'https://cdn.jsdelivr.net/npm/vant@next/lib/vant.min.js' },
  { local: 'lib/index.min.js', cdn: 'https://cdn.jsdelivr.net/npm/@vant/touch-emulator@1.3.2/index.min.js' },
  //{ local: 'lib/jszip.min.js', cdn: 'https://cdn.jsdelivr.net/npm/jszip@3.5.0/dist/jszip.min.js' },
  { local: 'lib/FileSaver.min.js', cdn: 'https://cdn.jsdelivr.net/npm/file-saver@2.0.2/dist/FileSaver.min.js' },
  //{ local: 'lib/xlsx.full.min.js', cdn: 'https://cdn.jsdelivr.net/npm/xlsx@0.16.8/dist/xlsx.full.min.js' },
  { local: 'app/tenvi.js', cdn: 'app/tenvi.js', stamp: true },
  { local: 'app/i18n.js', cdn: 'app/i18n.js', stamp: true },
  { local: 'app/store.js', cdn: 'app/store.js', stamp: true },
  { local: 'app/app.js', cdn: 'app/app.js', stamp: true },
];

/** 加载样式表 */
const loadStyleSheet = (path, suffix) => {
  let link = document.createElement('link');
  link.href = path + suffix;
  link.rel = 'stylesheet';
  link.type = 'text/css';
  document.getElementsByTagName('head')[0].appendChild(link);
}

/** 加载JS脚本 */
const loadScript = (path, suffix) => {
  document.write(`<script src="${path}${suffix}"><\/script>`);
}

// 根据环境选择js/css来源
let mode = ['127.0.0.1', 'localhost'].includes(window.location.hostname) ? 'local' : 'cdn';
let suffix = '?' + Date.now();
css.map(item => { loadStyleSheet(item[mode], item['stamp'] ? suffix : ''); });
js.map(item => {
  loadScript(item[mode], item['stamp'] ? suffix : suffix); 
});

// 线上环境屏蔽控制台输出
if (mode !== 'local') {
  if (!window.location.search.includes('console')) {
    console.log = (x) => { return; };
  }
}